package com.zhs.rabbitmq.routing;

import com.zhs.rabbitmq.utils.RabbitConstant;
import com.zhs.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zhenghuisheng
 * 发布者
 */
public class WeatherBureau {


    public static void main(String[] args) throws Exception {

        Map<String,String> map = new HashMap<String, String>();

        map.put("china.jiangxi.ganzhou.20220403", "中国江西赣州20220403天气数据");
        map.put("china.jiangxi.nanchang.20220403", "中国江西南昌20220403天气数据");
        map.put("china.jiangxi.jiujiang.20220404", "中国江西九江20220404天气数据");
        map.put("china.beijin.20220403", "中国北京20220403天气数据");

        map.put("china.guangdong.shenzhen.20220404", "中国广东深圳20220404天气数据");
        map.put("china.guangdong.guangzhou.20220403", "中国广东广州20220403天气数据");
        map.put("china.guangdong.dongguan.20220404", "中国广东东莞20220404天气数据");
        map.put("china.beijin.20220404", "中国北京20220404天气数据");


        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();


        Iterator<Map.Entry<String, String>> itr = map.entrySet().iterator();
        while (itr.hasNext()) {
            Map.Entry<String, String> me = itr.next();
            //第一个参数交换机名字   第二个参数作为 消息的routing key
            channel.basicPublish(RabbitConstant.EXCHANGE_WEATHER_ROUTING,me.getKey() , null , me.getValue().getBytes());

        }


        channel.close();
        connection.close();
    }

}
